<include file="Public/Header" />
<style>
	.disabled, .disabled:hover{background:#ccc; cursor: default;}
</style>
<link type="text/css" rel="stylesheet" href="__CSS__/jquery-tag.css" />
<table width="100%" height="31px" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
  <tr>
	<td height="31">
		<div class="titlebt">
			  分红设置
		</div>
	</td>
  </tr>
</table>
<div class="main">
	<div class="form">
		<form method='post' id="form_do" name="form_do" action="{:U('Finance/BonusConfig')}">
			<dl>
				<dt> <span class="red">* </span>利率设置：</dt>
				<dd>
					周利率：<input type="text" name="number" class="inp_one" id="number"  value="{$bonus_week_rate}" onkeyup="this.value=this.value.replace(/[^\d\.]/g,'')" style="width: 50px"/>% (0-100之间,最多允许4位小数）
					<input type="submit" class="btn_blue" id="releaseBtn" value="确认">
				</dd>
			</dl>
		</form>
	</div>
</div>

<table width="100%" height="31px" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table3">
	<tr>
		<td height="31">
			<div class="titlebt">
				分红日志
			</div>
		</td>
	</tr>
</table>
<div class="main">
	<div style="margin: 10px;">
		<input type="button" class="btn_blue" id="exec_bonus" value="执行分红">
		<b style="float: right;margin: 0 50px">累计分红总数： <span id="bonus_total" style="color: red;font-size:24px">{$bonus_total}</span></b>
	</div>
	<div class="list">
		<table width="100%">
			<tbody>
				<tr class="bonus-list-header">
					<th>流水号</th>
					<th>时间</th>
					<th>参与分红用户数</th>
					<th>参与分红通币总额</th>
					<th>参与分红通豆总额</th>
					<th>分红利率</th>
					<th>总分红数</th>
					<th>状态</th>
				</tr>
				<volist name="bonus_list" id="vo">
				<tr class="bonus-list">
					<td>{$vo.bonus_log_no}</td>
					<td>{$vo.bonus_log_date|date='Y-m-d H:i:s', ###}</td>
					<td>{$vo.bonus_log_user_num}</td>
					<td>{$vo.bonus_log_tong_num|price=###,false}</td>
					<td>{$vo.bonus_log_consumed_num|price=###,false}</td>
					<td>{$vo.bonus_log_rate|percents=###}</td>
					<td>{$vo.bonus_log_num|price=###,false}</td>
					<td>分红成功</td>
				</tr>
				</volist>
			</tbody>
		</table>
	</div>
	<div id="page-list" style="text-align: center"></div>
</div>
<include file="Public/Copyright" />
<script type="text/javascript" src="__PUBLIC__/Layerpage/laypage.js"></script>
<script type="text/javascript">
	//分页配置
	laypage({
		cont: 'page-list',
		pages: {$pages},
		first: 1,
		last: {$pages},
		prev: '<',
		next: '>',
		curr: function(){
			var page = location.search.match(/page=(\d+)/);
			return page ? page[1] : 1;
		}(),
		jump: function(e, first){ //
			if(!first){
				location.href = page() + e.curr;
			}
		}
	});

	function page(){
		var u = location.href;
		var r = '';
		if(u.indexOf('&') > 0){
			r = location.href.replace(/&page=\d+/, '');
			return r + '&page=';
		}else if(u.indexOf('?') > 0 ){
			if(u.indexOf('?page') > 0 ){
				r = location.href.replace(/\?page=\d+/, '');
				return r + '?page=';
			}else{
				return location.href + '&page=';
			}
		}else{
			return location.href + '?page=';
		}
	}

	//设置利率
	$('#releaseBtn').click(function(){
		var number = $.trim($('#number').val());
		var num = parseFloat(number);
		var reg = /^(\d*\.)?\d{0,4}$/;

		if( !reg.test(number) || num >= 100 || num <= 0 ){
			alert('请设置周利率在0-100%之间,并注意只允许有4位小数');
			return false;
		}

		if(! window.confirm('确认设置周利率为'+num+'%吗？')){
			return false;
		}
	});

	$('#exec_bonus').click(function(){
		var _btn = $(this);
		_btn.addClass('disabled');
		_btn.attr('disabled', 'disabled');
		_btn.val('执行中...');
		$.ajax("{:U('Finance/getBonusConfig')}", {
			type: 'post',
			success: function(data){
				if(window.confirm('当前分红周利率设置为：'+ data.rate + '%，确认执行分红操作吗？')){
					var l = $('.bonus-list').eq(0);
					var h = '';
					h += '<tr class="bonus-list">';
					h += '<td>'+ data.sn +'</td>';
					h += '<td>'+ data.datetime +'</td>';
					h += '<td><img src="__IMAGE__/loading.gif" width="20" height="20" /></td>';
					h += '<td><img src="__IMAGE__/loading.gif" width="20" height="20" /></td>';
					h += '<td><img src="__IMAGE__/loading.gif" width="20" height="20" /></td>';
					h += '<td>'+  data.rate +'%</td>';
					h += '<td><img src="__IMAGE__/loading.gif" width="20" height="20" /></td>';
					h += '<td><br /><img src="__IMAGE__/loading.gif" width="20" height="20" /><br/><span class="red">执行中<br />请不要关闭或刷新本页面<br /><br /></span></td>';
					h += '</tr>';
					l.before(h);

					// 执行分红
					$.ajax("{:U('Finance/Bonus')}", {
						type: 'post',
						success: function(data){
							var bl = $('.bonus-list').eq(0);
							if(data.code == 1){
								var log = data.log;
								var td = bl.find('td');
								td.eq(2).html(log.bonus_log_user_num);
								td.eq(3).html(log.bonus_log_tong_num);
								td.eq(4).html(log.bonus_log_consumed_num);
								td.eq(6).html(log.bonus_log_num);
								td.eq(7).html('分红成功');
								$('#bonus_total').html(log.bonus_total);
							}else{
								alert('本次分红操作失败，所有操作均已被取消');
								bl.remove();
							}
							_btn.removeClass('disabled');
							_btn.removeAttr('disabled');
							_btn.val('执行分红');
						}
					})
				}else{
					_btn.removeClass('disabled');
					_btn.removeAttr('disabled');
					_btn.val('执行分红');
				}
			}
		});
	});
</script>
</body>
</html>
